//
//  LCVerificationViewController.m
//  lechuang
//
//  Created by Mr_hi on 2023/4/3.
//  Copyright © 2023 Mooyi. All rights reserved.
//

#import "LCVerificationViewController.h"
#import "LCLoginService.h"

#import "LCResetPasswordViewController.h"

@interface LCVerificationViewController ()

@property (weak, nonatomic) IBOutlet UITextField *mobTfl;
@property (weak, nonatomic) IBOutlet UITextField *codeTfl;

@property (weak, nonatomic) IBOutlet UIButton *getYZMBtn;

@end

@implementation LCVerificationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (IBAction)backAction:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)getYZMBtnClicked:(UIButton *)sender {
    if (self.mobTfl.text.length <= 0) {
        [self showErrorText:@"请输入手机号码"];
    } else if ([NSString isMobileNumber:self.mobTfl.text] == NO) {
        [self showErrorText:@"请输入正确格式的手机号"];
    } else {
        [self showText:@"获取验证码中..."];
        [LCLoginService sendSessionCodeWithMobStr:self.mobTfl.text CodeType:@"FORGOT" Block:^(BOOL isSuccess) {
            if (isSuccess) {
                [sender startWithTime:60 title:@"重新获取" countDownTitle:@"s" mainColor:nil countColor:nil];
                [self dismissLoading];
            }
        }];
    }
}

- (IBAction)nextBtnAction:(UIButton *)sender {
    if (self.mobTfl.text.length <= 0) {
        [self showErrorText:self.mobTfl.placeholder];
    } else if ([NSString isMobileNumber:self.mobTfl.text] == NO) {
        [self showErrorText:@"请输入正确格式的手机号"];
    } else if (self.codeTfl.text.length <= 0) {
        [self showErrorText:self.codeTfl.placeholder];
    } else {
        [LCLoginService verificationWithMobStr:self.mobTfl.text Captcha:self.codeTfl.text Block:^(BOOL isSuccess, NSString *usertokey) {
            if (isSuccess) {
                LCResetPasswordViewController * pushVC = [LCResetPasswordViewController xx_instantiateFromStoryboardNamed:@"Login"];
                pushVC.mobStr = self.mobTfl.text;
                pushVC.usertokey = usertokey;
                [self.navigationController pushViewController:pushVC animated:YES];
            }
        }];
    }
}

@end
